#include <jni.h>
#include <stdio.h>
#include <stdlib.h>
#include <android/log.h>

#define  LOG_TAG    "omp"
#define  LOGW(...)  __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)

extern "C" {

void writeFile() {
    FILE *fp;
    char title[100];
    srand(100);
    int num = rand();
    sprintf(title, "/storage/emulated/0/qianzu/temp/test_%d.txt", num);
    fp = fopen(title, "w++");
    fprintf(fp, "This is testing for fprintf...\n" ) ;
    fputs( "This is testing for fputs...\n" , fp ) ;
    LOGW("Hello, world...file %d", num);
    fclose(fp);
}

JNIEXPORT void JNICALL
Java_com_versa_omp_Versa_destroy(JNIEnv *env, jobject thiz, jint modelIndex) {
    // destroy the Lua State
    LOGW("start to destroy......");

    #pragma omp parallel
    LOGW("Hello, world...");
    long i=0;
    #pragma omp parallel for private(i)
     for(i=0; i<10000000000; i++)
        LOGW("value %d", i);


//    int j=0;
//    #pragma omp parallel for private(j)
//    for(j=0; j<2; j++) {
//        FILE *fp;
//        char title[100];
//        sprintf(title, "/storage/emulated/0/qianzu/temp/test_%d.txt", j);
//        fp = fopen(title, "w++");
//        fprintf(fp, "This is testing for fprintf...\n" ) ;
//        fputs( "This is testing for fputs...\n" , fp ) ;
//        fclose(fp);
//    }
//    #pragma omp parallel
//    writeFile();
}

}